package com.hdw.job.batch.job;

import com.hdw.common.base.BaseException;
import com.hdw.job.batch.tasklet.AfterSQLExecTasklet;
import com.hdw.job.batch.tasklet.DelSQLExecTasklet;
import com.hdw.job.batch.writer.JDBCWriter;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.batch.core.step.tasklet.TaskletStep;
import org.springframework.batch.item.database.JdbcCursorItemReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class OdsAndDimJob extends BaseJob{


    @Autowired
    JDBCWriter jdbcWriter;

    public OdsAndDimJob() {
    }

    @Bean
    public Job hosToHdwJobBean() throws BaseException {
        TaskletStep beforeStep = this.buildBeforeStep();
        TaskletStep mainStep = this.buildMainStep();
        Job job = jobBuilderFactory.get("hosToHdwJobBean")
                .incrementer(new RunIdIncrementer())
                .start(beforeStep).next(mainStep)
                .build();
        return job;
    }


    protected TaskletStep buildMainStep() throws BaseException {
        TaskletStep step = stepBuilderFactory.get("main_step")
                .<Map, Map>chunk(1024)
                .reader(selfJdbcCursorItemReader)
                .writer(jdbcWriter)
                .build();
        return step;
    }
}
